home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 January - Disc 2 / Macworld (1999-01) (Disk 2).dmg / Shareware World / Utilities / User Interface / FinderPop175 / FinderPoplets / Source&API / FinderPopAPI.c next >
Encoding:
Text File  |  1998-10-13  |  3.1 KB  |  109 lines  |  [TEXT/CWIE]

  1. //=====================================================================================
  2. //    File:        FinderPopAPI.c
  3. //
  4. //    Contains:    FinderPop Application Programming Interface (Implementation)
  5. //
  6. //    Written by:    turly o’connor, cork, ireland        turly@geocities.com
  7. //
  8. //    Copyright:    1997, 1998 by Turlough O'Connor, all rights reserved.
  9. //
  10. //    Change History (most recent first):
  11. //        <02>    23-Sep-98    tur        Add FinderPoplets!
  12. //        <01>    01-Sep-98    tur        Make Beta Version publicly available.
  13. //
  14. //=====================================================================================
  15.  
  16. #include <Gestalt.h>
  17. #include <Errors.h>
  18. #include "FinderPopAPI.h"
  19.  
  20.  
  21. //=====================================================================================
  22. // OpenFinderPopConnection
  23. //
  24. //    Opens a FinderPop "connection" (in reality a ProcPtr to the internal FinderPop
  25. //    routine which handles the connection.)  This routine is 68K, so on a PowerMac,
  26. //    we allocate a RoutineDescriptor which is returned as the "cookie", so make sure
  27. //    you dispose of it by calling CloseFinderPopConnection() - q.v.
  28. //
  29. //=====================================================================================
  30.  
  31. TFinderPopCookie OpenFinderPopConnection(void)
  32. {
  33.     long    fp;
  34.  
  35.     if (Gestalt(kFinderPopAPIGestaltSignature, &fp) != noErr)
  36.         fp = 0;
  37.     else
  38.     if (fp != 0)
  39.         fp = *((long *)fp);        // sorry guys -- the other fields are private :-)
  40.  
  41. #if GENERATINGPOWERPC
  42.     if (fp != 0)                // create a RoutineDescriptor for the 68K code pointed to by FP
  43.     {                            // Ahem -- in the system heap, please...!
  44.         THz    oldZone = GetZone();
  45.         SetZone(SystemZone());
  46.         UniversalProcPtr apiProc = NewRoutineDescriptor((ProcPtr)fp, uppFinderPopAPIProcInfo, kM68kISA);
  47.         SetZone(oldZone);
  48.         fp = (long)apiProc;
  49.     }
  50. #endif    /* GENERATINGPOWERPC */
  51.  
  52.     return (TFinderPopCookie)fp;
  53. }
  54.  
  55.  
  56. /**/
  57.  
  58.  
  59. //=====================================================================================
  60. // CloseFinderPopConnection
  61. //
  62. //    For PowerMacs, dispose of the cookie routine descriptor.  Always return zero.
  63. //
  64. //=====================================================================================
  65.  
  66. TFinderPopCookie CloseFinderPopConnection(TFinderPopCookie fpCookie)
  67. {
  68. #if GENERATINGPOWERPC
  69.     if (fpCookie != 0)
  70.         DisposeRoutineDescriptor((UniversalProcPtr)fpCookie);
  71. #endif
  72.  
  73.     return 0;
  74. }
  75.  
  76.  
  77. /**/
  78.  
  79.  
  80. //=====================================================================================
  81. // FinderPopAPIProc
  82. //
  83. //    Use the cookie which points at the internal FinderPop routine to handle the
  84. //    3rd-party API.  Basically, pass the buck to FinderPop's FinderPopPrefsProc()
  85. //    routine.
  86. //
  87. //=====================================================================================
  88.  
  89. SInt32 FinderPopAPIProc(TFinderPopCookie fpCookie, UInt32 selector, SInt32 param)
  90. {
  91.     SInt32    result;
  92.  
  93.     if (fpCookie != 0) 
  94.     {
  95. #if GENERATINGPOWERPC
  96.         result = CallUniversalProc((UniversalProcPtr)fpCookie, uppFinderPopAPIProcInfo, selector, param);
  97. #else
  98.         typedef pascal SInt32 (*TInternalFinderPopAPIProc)(UInt32 selector, SInt32 param);
  99.         result = ((TInternalFinderPopAPIProc)fpCookie)(selector, param);
  100. #endif
  101.     }
  102.     else
  103.         result = paramErr;
  104.  
  105.     return result;
  106. }
  107.  
  108. /* EOF FinderPopAPI.c */
  109.